#ifndef CLIENTTRANSFER_H
#define CLIENTTRANSFER_H


#include <QObject>
#include <QUdpSocket>
#include <QTimer>
#include <QMutex>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include "ImageTransferProtocol.h"

class ClientTransfer : public QObject
{
    Q_OBJECT
public:
    ClientTransfer();
public slots:
    void setServer(QHostAddress addr, quint16 port);
    void timerRequest();
    void recvData();
    void imgRequest(int timestamp, int seq, int width, int height, int once_count);
    void trackRequest(int timestamp, int x1, int y1, int x2, int y2);
    void ptzRequest(int x, int y, int z);
signals:
    void gotResponse(QByteArray response);
    void gotImageData(QByteArray image_data);

private:
    void processDatagram(QByteArray datagram);
    void sendRequest();

    QUdpSocket m_sock;

    QTimer m_timer;
    QByteArray m_request;
    QHostAddress m_server_addr;
    quint16 m_server_port;

    QMutex m_req_mutex;

};

#endif // CLIENTTRANSFER_H
